<?php


namespace app\api\controller\v9;


use app\api\controller\v2\Auth;
use app\common\model\ZlAstr;
use app\common\model\ZlUserAttention;
use app\common\lib\exception\ApiException;
use think\response\Json;


class Astr extends Auth
{
    /**
     * 占星师个人主页
     * @return Json
     * @throws \Exception
     */
    public function home()
    {
        $auid = input('auid', $this->user['auid'] ?? '');

        $astrInfo = (new ZlAstr())->getInfoById($auid);

        if (!$astrInfo)
        {
            return show(config('code.error'), '占星师不存在');
        }

        $isSelf = $this->user['id'] == $astrInfo['uid'] ? 1 : 0;

        $attentionStatus = $isSelf ? 0 : (new ZlUserAttention())->andAstrStatusOfAttention($this->user['id'], $astrInfo['uid']);

        $data = [
            'is_self' => $isSelf,
            'nickname' => $astrInfo['nickname'],
            'avatar' => $astrInfo['avatar'],
            'sex' => (int)$astrInfo['sex'],
            'astr_level' => (int)$astrInfo['astr_level'],
            'attention_status' => (int)$attentionStatus,
            'is_inviter' => (int)$astrInfo['is_inviter'],
            'is_astr' => (int)$astrInfo['is_astr'],
            'is_zxdr' => (int)$astrInfo['is_zxdr'],
            'attention_num' => (int)$astrInfo['attention_num'],
            'fans_num' => (int)$astrInfo['fans_num'],
            'bg_index' => (int)$astrInfo['bg_index'],
        ];

        return show(config('code.success'), '个人主页', $data);
    }

    /**
     * 占星师 文章列表
     * @return array|mixed
     * @throws \Exception
     */
    public function article()
    {
        $auid = input('auid', $this->user['auid'] ?? '');
        $astrModel = new ZlAstr();
        $astrInfo = $astrModel->getInfoById($auid);

        $articelDatas = $astrModel->getArticleIdPaginat($astrInfo['uid'], $this->user['uc_id']);

        return show(config('code.success'),'文章列表',$articelDatas);
    }
}
